package com.example.spinning.config;


import java.io.IOException;
import java.util.Properties;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.stereotype.Component;
/*

 * 读取属性文件的属性信息

 */

@Component
public class SystemConfig {
    private static Properties props;
    //在类构造函数中读取属性文件
    public SystemConfig(){
        Resource resource = new ClassPathResource("application.properties");

        try {

            props=PropertiesLoaderUtils.loadProperties(resource);

        } catch (IOException e) {

            e.printStackTrace();

        }

    }

    public static String getProperty(String key){

        return props == null ? null :  props.getProperty(key);

    }

    public static String getProperty(String key,String defaultValue){

        return props == null ? null : props.getProperty(key, defaultValue);

    }

    public static Properties getProperties(){

        return props;

    }

}

